package cn.com.customer.manager.adapter

import android.text.Editable
import android.text.TextWatcher
import android.view.View.OnFocusChangeListener
import android.widget.EditText
import cn.com.customer.manager.R
import cn.com.customer.manager.bean.BackMoneyInfo
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.BaseViewHolder


class RecordAddAdapter(rid: Int) : BaseQuickAdapter<BackMoneyInfo, BaseViewHolder>(rid) {
    override fun convert(helper: BaseViewHolder?, item: BackMoneyInfo?) {
        helper?.let {
            var recordTime = it.getView<EditText>(R.id.record_time_content)
            var recordPrice = it.getView<EditText>(R.id.record_price_content)
            var recordRemark = it.getView<EditText>(R.id.record_remark)
           
            item?.let {
                recordTime.setText(item.receivedDate)
                recordPrice.setText(item.receivedAmount)
                recordRemark.setText(item.remark)
                //goodName.addTextChangedListener(TxtWatcher().buildWatcher(item,goodName))
                recordTime.addTextChangedListener(TxtWatcher().buildWatcher(item,recordTime))
                recordPrice.addTextChangedListener(TxtWatcher().buildWatcher(item,recordPrice))
                recordRemark.addTextChangedListener(TxtWatcher().buildWatcher(item,recordRemark))
             
            }

        }
    }

    class TxtWatcher : TextWatcher {
        private var recordInfo: BackMoneyInfo? = null
        private lateinit var et: EditText

        fun buildWatcher(item: BackMoneyInfo?, et: EditText): TxtWatcher {
            this.recordInfo = item
            this.et = et
            return this
        }
        override fun beforeTextChanged(s: CharSequence, start: Int, count: Int, after: Int) {}
        override fun onTextChanged(s: CharSequence, start: Int, before: Int, count: Int) {
            if (s.isNotEmpty()) {
                when (et.id) {
                    R.id.record_time_content -> {
                        recordInfo?.receivedDate = s.toString()
                    }
                    R.id.record_price_content -> {
                        recordInfo?.receivedAmount = s.toString()
                    }
                    R.id.record_remark->{
                        recordInfo?.remark = s.toString()
                    }

                }
            } else {

            }
        }

        override fun afterTextChanged(s: Editable) {}
    }
}